import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {LocalStorage} from "../../app.local-storage";
import {ROUTE} from "../../service/route.service";
import {PAYMENT} from "../../service/payment.service";
import {CheckStandModel} from "../../model/checkstand.model";

@Component({
  selector: 'app-wechat-payment-view',
  templateUrl: './wechat-payment-view.component.html',
  styleUrls: ['./wechat-payment-view.component.scss']
})
export class WechatPaymentViewComponent implements OnInit {

  checkstand:CheckStandModel;
  qrcode:any;
  timer:any;

  constructor(private routeInfo:ActivatedRoute,
              private localStorage:LocalStorage,
              private PAYMENT:PAYMENT,
              private ls:LocalStorage,
              private route:ROUTE) {
    this.checkstand = this.ls.getObject('checkstand')as CheckStandModel;


  }

  ngOnInit() {
    this.timer = setInterval(()=>{this.getStatus()},5000);
    this.routeInfo.params.subscribe((param:any)=>{
      this.qrcode = param.pay_info;
    });
  }
  goToHomeView(){
    window.history.back();
  }
  getStatus(){
    this.PAYMENT.queryStatus(this.checkstand.billNo,(res:any)=>{
      if(res){
        clearInterval(this.timer);
        console.log("clearInterval");
        this.route.goFinishedPaymentView();
        console.log("goFinishedPaymentView");
      }else{
        console.log(2);
      }
    })
  }

}
